package com.tedu.jsd2407_ivos_fzj.application.controller;

import com.tedu.jsd2407_ivos_fzj.application.pojo.dto.ApplicationQuery;
import com.tedu.jsd2407_ivos_fzj.application.pojo.dto.ApplicationSaveParam;
import com.tedu.jsd2407_ivos_fzj.application.pojo.vo.ApplicationVO;
import com.tedu.jsd2407_ivos_fzj.application.service.ApplicationService;
import com.tedu.jsd2407_ivos_fzj.base.response.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;

@RequestMapping("/v1/application")
@RestController
@Slf4j
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult save(ApplicationSaveParam applicationSaveParam){
        log.debug("保存申请表，参数：{}",applicationSaveParam);
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult select(ApplicationQuery applicationQuery){
        log.debug("查询申请单，参数：{}",applicationQuery);
        List<ApplicationVO> applicationVOList = applicationService.select(applicationQuery);
        log.debug("申请单集合，参数{}",applicationVOList);
        return JsonResult.ok(applicationVOList);
    }
    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable Long id){
        log.debug("撤销申请，参数：{}",id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }
    @PostMapping("distribute/{applicationId}/{vehicleId}")
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("车辆分配，参数：{}，{}",applicationId,vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }
    @PostMapping("repaid/{applicationId}/{vehicleId}")
    public JsonResult repaid(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("还车，参数：{}，{}",applicationId,vehicleId);
        applicationService.repaid(applicationId,vehicleId);
        return JsonResult.ok();
    }

}
